
import java.util.Arrays;
import java.util.Scanner;

public class HihoCoder1467 {

	static String[] time;
	static String[][] value;
	static boolean[] has;
	static int m;
	static int result = 0;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		for (; num > 0; num--) {
			result = 0;
			int n = in.nextInt();
			m = in.nextInt();
			value = new String[m][2];
			for (int i = 0; i < m; i++) {
				value[i][0] = in.next();
				value[i][1] = in.next();
			}
			handle(n, m);
			if (result > 0) {
				System.out.println("GOOD");
			} else {
				System.out.println("BAD");
			}

		}
	}

	public static void handle(int n, int m) {
		has = new boolean[m + 1];
		time = new String[m];
		DFS(0);
	}

	private static boolean DFS(int i) {
		if (i > 3 && checkOut()) {
			result++;
		}
		if (i < 4) {
			for (int z = 0; z < 2; z++) {
				if(Arrays.asList(time).contains(value[i][z])){
					time[i] = value[i][z];
				}
				DFS(i + 1);
				time[i] = null;
			}
		}
		return false;

	}

	private static boolean checkOut() {
		for (String v : time) {
			if (v != null) {
				String[] a = v.split("");
				int index = Integer.parseInt(a[2]);
				if (!has[index]) {
					has[index] = true;
				} else {
					has = new boolean[m + 1];
					return false;
				}
			}
		}
		has = new boolean[m + 1];
		return true;
	}

}
